package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.model.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author terminal
 * @since 2023-06-08 13:28
 */
@RestController
@RequestMapping("/admin/product")
public class BaseCategoryTrademarkController {
    @Resource
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    /**
     * 查询指定分类下包含品牌列表
     * @param category3Id
     * @return
     */
    @GetMapping("/baseCategoryTrademark/findTrademarkList/{category3Id}")
    public Result getTrademarkList(@PathVariable("category3Id") Long category3Id){
        List<BaseTrademark> list = baseCategoryTrademarkService.getTrademarkList(category3Id);
        return Result.ok(list);
    }

    /**
     * 查询指定分类下未关联品牌列表(可选品牌列表)
     * @param category3Id
     * @return
     */
    @GetMapping("/baseCategoryTrademark/findCurrentTrademarkList/{category3Id}")
    public Result getCurrentTrademarkList(@PathVariable("category3Id") Long category3Id){
        List<BaseTrademark> list = baseCategoryTrademarkService.getCurrentTrademarkList(category3Id);
        return Result.ok(list);
    }

    /**
     * 保存分类品牌关联
     * @param categoryTrademarkVo
     * @return
     */
    @PostMapping("/baseCategoryTrademark/save")
    public Result save(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
        baseCategoryTrademarkService.saveBaseCategoryTrademark(categoryTrademarkVo);
        return Result.ok();
    }

    /**
     * 删除指定分类下品牌
     * @param category3Id
     * @param trademarkId
     * @return
     */
    @DeleteMapping("/baseCategoryTrademark/remove/{category3Id}/{trademarkId}")
    public Result remove(@PathVariable("category3Id") Long category3Id,
                         @PathVariable("trademarkId") Long trademarkId){
        baseCategoryTrademarkService.removeCategoryTrademark(category3Id,trademarkId);
        return Result.ok();
    }


}
